package lvcy.message.sender;

import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import lvcy.message.http.HttpClientGenerator;
import lvcy.message.thread.CountableThreadPool;

public class JstMessageSender implements MessageSender{

	private Logger log=LogManager.getLogger(DxtMessageSender.class);
	private String requestUrl;
	private String postData;
	private JstMessageSender(String requestUrl,String postData) {
		this.requestUrl=requestUrl;
		this.postData=postData;
	}
	@Override
	public void send() throws InterruptedException {
		
		CountableThreadPool.INSTANCE.execute(this);
	}
	@Override
	public void run() {
		try{
			CloseableHttpClient httpClient=HttpClientGenerator.getInstance().getHttpClient();
			HttpPost httpPost=new HttpPost(this.requestUrl);
			StringEntity stringEntity=new StringEntity(this.postData);
			httpPost.setEntity(stringEntity);
			HttpResponse response=httpClient.execute(httpPost);
			handleResponse(response);
		}catch(Exception e){
			log.error(e);
		}
		
	}
	private void handleResponse(HttpResponse response){
		log.info("// TODO");
	}
}
